<template>
  <div class="warn-wrap" v-show="showWarn">
    <div class="warn-box">
      <div class="title">{{title}}</div>
      <div class="warn-con">{{content}}</div>
      <div class="warn-btn" v-if="type == 1">
        <div class="left-btn" @click="closeBtn">
          <button type="button" class="cancel">{{cancelText}}</button>
        </div>
        <div class="right-btn" @click="confirmBtn">
          <button type="button" class="sure">{{confirmText}}</button>
        </div>
      </div>
      <div class="warn-btn" v-if="type == 2">
        <div class="confirm-box" @click="confirmBtn">
          <button type="button" class="confirm">{{confirmText}}</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    props: {
      value: {},
      type: {
        type: String,
        default: "2"
      },
      title: {
        type: String,
        default: '温馨提示'
      },
      content: {
        type: String,
        default: ''
      },
      cancelText: {
        type: String,
        default: '取消'
      },
      confirmText: {
        type: String,
        default: '确认'
      },
    },
    data() {
      return {
        showWarn: false
      }
    },
    methods: {
      closeBtn() {
        this.showWarn = false;
        this.$emit('cancel');
      },
      confirmBtn() {
        this.showWarn = false;
        this.$emit('confirm');
      },
    },
    mounted() {
      this.showWarn = this.value;
    },
    watch: {
      value(newVal, oldVal) {
        this.showWarn = newVal;
      },
      showWarn(val) {
        this.$emit('input', val);
      }
    }
  }
</script>

<style lang="stylus" scoped>
  .warn-wrap
    position: fixed
    top: 0
    left: 0
    right: 0
    bottom: 0
    z-index: 100
    display: flex
    align-items: center
    justify-content: center
    background-color: rgba(0, 0, 0, 0.5)
    .warn-box
      position: relative
      width: 7.32rem
      height: 4.627rem
      background: rgba(255, 255, 255, 1)
      border-radius: 0.173rem
      box-sizing: border-box
      .title
        display: flex
        align-items: center
        justify-content: center
        width: 100%
        height: 1.32rem
        background: rgba(60, 175, 255, 1)
        font-size: 0.48rem
        color: rgba(255, 255, 255, 1)
        border-radius: 0.173rem 0.173rem 0rem 0rem
      .warn-con
        display: flex
        align-items: center
        justify-content: center
        margin: 0 auto
        width: 85%
        height: 2.12rem
        font-size: 0.387rem
        color: rgba(27, 27, 27, 1)
      .warn-btn
        display: flex
        width: 100%
        height: 1.187rem
        border-top: 1px solid rgba(230, 230, 230, 1)
        .left-btn
          width: 3.667rem
          height: 1.173rem
          border-right: 1px solid rgba(230, 230, 230, 1)
          .cancel
            border-radius: 0rem 0rem 0rem 0.173rem
            width: 100%
            height: 1.173rem
            line-height: 1.173rem
            font-size: 0.44rem
            color: rgba(146, 146, 146, 1)
            background: #FFF
        .right-btn
          width: 3.653rem
          height: 1.173rem
          .sure
            border-radius: 0rem 0rem 0.173rem 0rem
            width: 100%
            height: 1.173rem
            line-height: 1.173rem
            font-size: 0.44rem
            color: rgba(60, 175, 255, 1)
            background: #FFF
        .confirm-box
          width: 100%
          height: 1.173rem
          .confirm
            border-radius: 0rem 0rem 0.173rem 0.173rem
            width: 100%
            height: 1.173rem
            line-height: 1.173rem
            font-size: 0.44rem
            color: rgba(60, 175, 255, 1)
            background: #FFF
</style>
